package com.example.bianpan;

import com.example.bianpan.context.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

@Component
public class ProcessEngin {

    @Autowired
    private  ProcessNodesFactory processNodesFactory;

    /**
     * 将上下文交给流程节点处理，并返回上下文
     * @param operation
     * @param context
     * @return
     */
    public Context process(String operation,Context context)
    {
        Set<Node> nodes = processNodesFactory.get(operation);

        for (Node node:nodes)
        {
            node.process(context);
        }
        return context;


    }

    public  <C extends  Context,R> ProcessInstance<C,R> fire(String operation){
        return  new ProcessInstance<C,R>(operation,this);
    }
}
